package com.easy.service.impl;

import com.easy.bean.Member;
import com.easy.mapper.MemberDao;
import com.easy.service.LoginService;
import com.easy.util.PasswordUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    MemberDao memberDao;
    @Override
    public String login(Member member) {
        //登录逻辑
        //1通过用户名查询数据库
        Member result=memberDao.getByPhone(member.getPhone());
        if(result==null){
            throw new RuntimeException("登录异常");
        }
        //2.验证密码
        String password=member.getPassword();//123123
        String encryptionPassword=result.getPassword();
        if(!PasswordUtil.checkPassword(password,encryptionPassword)){
            throw new RuntimeException("登录异常");
        }
        //3.返回结果token
        return "success";
    }
}
